package com.to.aboomy.banner;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Image;
import ohos.app.Context;

/**
 * 使用Glide 加载动画会有闪屏的问题
 *
 * @since 2021-07-21
 */
public class ImageHolderCreator implements HolderCreator {
    @Override
    public Component createView(Context context, int integer, int index) {
        Image iv = new Image(context);
        ComponentContainer.LayoutConfig layoutConfig =
                new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,
                        ComponentContainer.LayoutConfig.MATCH_PARENT);
        iv.setLayoutConfig(layoutConfig);
        iv.setScaleMode(Image.ScaleMode.STRETCH);
        Glide.with(context).load(integer)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .skipMemoryCache(true)
                .into(iv);
        return iv;
    }
}